<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
unset($chk);
if ($curruser['acl'] != "255" || $curruser['account'] != G_SUPERACCOUNT)
{
    exit();
}
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$conf = new Config();
$ui = new UI_3D(true);
$tpl = new Template2();
$gType = chkGametype($gametype);
$OpenNumFieldsArr = array(20 => "(n5+n4+n3+n2+n1)", 21 => "(n8+n7+n6+n5+n4+n3+n2+n1)", 22 => "(n8+n7+n6+n5+n4+n3+n2+n1)", 23 => "(n8+n7+n6+n5+n4+n3+n2+n1)");
switch ($gType)
{
    case 3 :
        include( "class_5h/class.lotto5h.php" );
        $OpenNumFields = $OpenNumFieldsArr[$gametype];
        break;
	case 4 :
        include( "class_sb/class.lottosb.php" );
        $OpenNumFields ="(n3+n2+n1)";
        break;
    default :
        include( "class_3d/class.lotto3d.php" );
        $OpenNumFields = "(n3+n2+n1)";
        break;
}
include( "class/function_3d.php" );
$open1 = "";
$open2 = "";
$openid01 = "";
$paperDateChkStr1 = "";
$paperDateChkStr2 = "";
$msg = "";
$msgB = "";
$postTime = $conf->get("paper_post_bet");
$today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
$msgSummary = "";
$openSummary = $today;
if (ispost() && getvar("rType") == "1")
{
    $paperDate = intval(getvar("paperDate"));
    $open = getvar("open1");
    if ($open != "" && !is_date($open))
    {
        exit("error date");
    }
    switch ($paperDate)
    {
        case 1 :
            $open1 = $open;
            $arrTemp = array();
            $paperDateChkStr1 = "checked";
            if ($open == "")
            {
                $msg = "<fon color=red>报表日不可空白</font>";
                break;
            }
            $i = 1;
            while ($i < count($g_gametype_3d))
            {
                if ($gType == 4)
                {
                    $lotto3d = new lotto5h($i);
                }
                else
                {
                    $lotto3d = new lotto3d($i);
                }
                $tbl2 = $g_gametype_3d[$i]['en'];
                $sql = "SELECT id FROM lotto_{$tbl2} WHERE open = '{$open}' and {$OpenNumFields}>=0";
                $rs = getdb($sql);
                while (!$rs->eof)
                {
                    $id = $rs->f['id'];
                    $fields = array();
                    $fields['state'] = "1";
                    if (2 < $i)
                    {
                        $fields['calcbet'] = "1";
                    }
                    db_update("lotto_{$tbl2}", $fields, "id={$id}");
                    $lotto_id = $lotto3d->CheckLottoOpen($id);
                    $x = $lotto3d->openDate == $today ? "" : "x";
                    if ($lotto_id == $id)
                    {
                        $lotto3d->OpenProcess($lotto_id, $x);
                        if (2 < $i)
                        {
                            db_update("lotto_{$tbl2}", array("calcbet" => "0"), "id={$id}");
                        }
                    }
                    else
                    {
                        $arrTemp[] = "{$lotto_id} == {$id}";
                    }
                    $rs->next();
                }
                $msg = "<fon color=red>报表日{$open}重新颁奖过帐完成！</font>";
                ++$i;
            }
            break;
        case 2 :
            $arrTemp = array();
            $open = getvar("open2");
            $open2 = $open;
            $openid01 = getvar("openid01");
            $paperDateChkStr2 = "checked";
            if ($open2 == "" || $openid01 == "")
            {
                $msg = "<font color=red>报表日或时间不可空白！</font>";
                break;
            }
            $i = 3;
            while ($i < count($g_gametype_3d))
            {
                if ($gType == 4)
                {
                    $lotto3d = new lotto5h($i);
                }
                else
                {
                    $lotto3d = new lotto3d($i);
                }
                $tbl2 = $g_gametype_3d[$i]['en'];
                $sql = "SELECT id FROM lotto_{$tbl2} WHERE open = '{$open}' and openbet <= '{$openid01}' and {$OpenNumFields}>=0";
                $rs = getdb($sql);
                while (!$rs->eof)
                {
                    $id = $rs->f['id'];
                    $fields = array();
                    $fields['state'] = "1";
                    $fields['calcbet'] = "1";
                    db_update("lotto_{$tbl2}", $fields, "id={$id}");
                    $lotto_id = $lotto3d->CheckLottoOpen($id);
                    $x = $lotto3d->openDate == $today ? "" : "x";
                    if ($lotto_id == $id)
                    {
                        $lotto3d->OpenProcess($lotto_id, $x);
                        db_update("lotto_{$tbl2}", array("calcbet" => "0"), "id={$id}");
                    }
                    else
                    {
                        $arrTemp[] = "{$lotto_id} == {$id}";
                    }
                    $msg = "<font color=red>报表日「{$open}」开奖时间「{$openid01}」之前之期数重新颁奖过帐完成！</font>";
                    $rs->next();
                }
                ++$i;
            }
            break;
    }
}
else if (ispost() && getvar("rType") == "2")
{
    include_once( "class_3d/postBetToXBet_3d.php" );
    $msgB = postBetToXBet(1);
    $conf->set("systemcheck", 0);
    $msgB .= "手动过帐注单完成";
}
else if (ispost() && getvar("rType") == "3")
{
    $openSummary = getvar("openSummary");
    if ($openSummary != "" && !is_date($openSummary))
    {
        exit("error date");
    }
    include_once( "class_3d/postBetToXBet_3d.php" );
    $msgSummary = postBetToSummary($openSummary, 0 - 1);
    $conf->set("systemcheck", 0);
    $msgSummary .= "手动产生汇总清单完成";
}
$ui->header();
if ($gType)
{
    include( "admin_menu_3d.php" );
}
else
{
    include( "admin_menu.php" );
}
echo "<style> th{font-size:12px;}</style>";
if ($gType)
{
    echo "<form action=\"\" method=\"post\">";
    echo "<input type=\"hidden\" value=\"1\" name=\"rType\" />";
    echo "<table class='tblMy3D' width=\"700\">";
    echo "<tr class='td0 bgClc_{$gametype}' ><th colspan=2>[所有时时彩]重新颁奖过帐</th></tr>";
    if ($msg != "")
    {
        echo "<tr  class=td2 ><th colspan=2>{$msg}</th></tr>";
    }
    echo "<tr class=td2><th class='td0 bgClc_{$gametype}' align=right width=\"200\"><label>[福体 与 时时彩] 报表日<input type=radio value=1 name=paperDate {$paperDateChkStr1}></label></th><td><input type=text name=open1 value=\"{$open1}\"></td></tr>";
    echo "<tr class=td2><th class='td0 bgClc_{$gametype}' align=right><label>[时时彩] 某开奖时间之前(含)<input type=radio value=2 name=paperDate {$paperDateChkStr2}></label></th><td>报表日 <input type=text name=open2 value=\"{$open2}\"> 开奖时间<input type=text name=openid01 value=\"{$openid01}\"> 之前</td></tr>";
    echo "<tr class=td2 ><th colspan=2><ul><li>报表日格式 000-00-00</li><li>开奖时间格式 0000-00-00 00:00:00</li></ul></th></tr>";
    echo "<tr class='td0 bgClc_{$gametype}' ><th colspan=2 align=center><input type=\"submit\" value=\"送出\" /></th></tr>";
    echo "</table>";
    echo "</form>";
    echo "<form action=\"\" method=\"post\">";
    echo "<input type=\"hidden\" value=\"2\" name=\"rType\" />";
    echo "<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" width=\"600\">";
    echo "<tr><th class=\"td0 bgClc_{$gametype}\" width=\"200\">手动过帐注单</th><td class=td2><input type=\"submit\" value=\"注单过帐\" /></td></tr>";
    if ($msgB != "")
    {
        echo "<tr  class=td2 ><th colspan=2 class=green>{$msgB}</th></tr>";
    }
    echo "</table>";
    echo "</form>";
}
echo "<form action=\"\" method=\"post\">";
echo "<input type=\"hidden\" value=\"3\" name=\"rType\" />";
echo "<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" width=\"600\">";
echo "<tr><th class=\"td0 bgClc_{$gametype}\" width=\"200\">手动产生汇总清单</th><td class=td2>报表日 <input type=text name=openSummary value=\"{$openSummary}\"><input type=\"submit\" value=\"注单汇总\" /></td></tr>";
if ($msgSummary != "")
{
    echo "<tr  class=td2 ><th colspan=2 class=green>{$msgSummary}</th></tr>";
}
echo "</table>";
echo "</form>";
$ui->footer();
?>